package com.mallcai.bigdata.ladon.service.report.impl.handler.support.rule;

import com.mallcai.bigdata.ladon.dpl.vo.DataType;

import java.util.Collection;
import java.util.Objects;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-07-22 09:34
 */
public class InOperator extends AbstractCollectionRuleOperator {

    private static final String[] COMMANDS = {"in"};

    @Override
    public boolean innerTest(Collection obj1, Collection obj2) {
        if (obj1.size() > obj2.size()){
            return false;
        }
        return obj1.stream().allMatch(o1 -> obj2.stream().anyMatch(o2->Objects.equals(o1, o2)));
    }

    @Override
    public String[] getCommands() {
        return COMMANDS;
    }

    @Override
    public DataType[] getSupportDataTypes() {
        return IRuleOperator.ALL_DATA_TYPE;
    }
}
